package plus.decl;

import java.util.List;

import plus.Gripe;
import plus.Type;
import plus.VScope;

public class Segment {
	List<String> names;
	TypeSpec typespec;
	public Segment(List<String> names) { this(names, null); }
	public Segment(List<String> names, TypeSpec spec) {
		this.names = names;
		this.typespec = spec;
	}
	public int nameCount() { return names.size(); }
	public int enterParams(Type[] domain, int p) {
		if (null == typespec) {
			for (String name: names) {
				VScope.current.add_param(name, Gripe.lineNr, domain[p]);
				p++;
			}
		} else {
			Type type = typespec.interpret();
			for (String name: names) {
				// TODO only set bounds on an otherwise free type.
				Type.unify(domain[p], type);
				VScope.current.add_param(name, Gripe.lineNr, domain[p]);
				p++;
			}
		}
		return names.size();
	}
}
